package com.knoya.chejian.pda.module.shezhi

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import android.widget.AdapterView
import com.knoya.chejian.pda.R
import com.knoya.chejian.pda.activity.BaseActivity
import com.knoya.chejian.pda.minterface.MainButtonInterface
import com.knoya.chejian.pda.myadapter.MainButtonAdapter
import com.knoya.chejian.pda.mydialog.MyAlerDialog
import kotlinx.android.synthetic.main.activity_shezhi.*
import kotlinx.android.synthetic.main.header_knoya.*

class ShezhiActivity : BaseActivity(), MainButtonInterface, View.OnClickListener {



    lateinit var listbutton: MutableList<String>
    lateinit var sgvShezhiAdapter : MainButtonAdapter
    override fun getLayoutId(): Int {
        return R.layout.activity_shezhi
    }

    override fun initCreate() {
        tv_header_title.text = "设置"
        iv_header_left.visibility = View.VISIBLE
        iv_header_left.setOnClickListener(this)
        listbutton = ArrayList()
        listbutton.add("仓位过滤")
        listbutton.add("选择界面")
        sgvShezhiAdapter = MainButtonAdapter(listbutton,this,this)
        GvShezhi.adapter = sgvShezhiAdapter
    }

    override fun onbutton(data: String) {
        when(data){
            "仓位过滤" -> {
                val intent = Intent(this@ShezhiActivity, WeizhiShezhiActivity::class.java)
                intent.putExtra("code",1)
                startActivity(intent)
            }
            "选择界面" -> {
                val myAlerDialog = MyAlerDialog(this)
                myAlerDialog.start()
                myAlerDialog.setdata("确定要更换界面吗？")
                myAlerDialog.setleft("界面1") {
                    editor.putInt("jiemian",1)
                    editor.commit()
                    myAlerDialog.getdialog().dismiss()
                }
                myAlerDialog.setright("界面2") {
                    editor.putInt("jiemian",2)
                    editor.commit()
                    myAlerDialog.getdialog().dismiss()
                }
                myAlerDialog.show()
            }
        }
    }
    override fun onClick(v: View?) {
        when(v){
            iv_header_left -> {
                finish()
            }
        }
    }
}
